package com.ruoyi.garbage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.garbage.domain.KeywordSearchNum;
import com.ruoyi.garbage.service.IKeywordSearchNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 搜索关键词+次数记录Controller
 *
 * @author 刘哲贤
 * @date 2023-01-07
 */
@RestController
@RequestMapping("/admin/keywordSearchNum")
public class KeywordSearchNumController extends BaseController {
    @Autowired
    private IKeywordSearchNumService keywordSearchNumService;

    /**
     * 查询搜索关键词+次数记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordSearchNum:list')")
    @GetMapping("/list")
    public TableDataInfo list(KeywordSearchNum keywordSearchNum) {
        startPage();
        List<KeywordSearchNum> list = keywordSearchNumService.selectKeywordSearchNumList(keywordSearchNum);
        return getDataTable(list);
    }

    /**
     * 导出搜索关键词+次数记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordSearchNum:export')")
    @Log(title = "搜索关键词+次数记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KeywordSearchNum keywordSearchNum) {
        List<KeywordSearchNum> list = keywordSearchNumService.selectKeywordSearchNumList(keywordSearchNum);
        ExcelUtil<KeywordSearchNum> util = new ExcelUtil<KeywordSearchNum>(KeywordSearchNum.class);
        util.exportExcel(response, list, "搜索关键词+次数记录数据");
    }

    /**
     * 获取搜索关键词+次数记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordSearchNum:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(keywordSearchNumService.selectKeywordSearchNumById(id));
    }

    /**
     * 新增搜索关键词+次数记录
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordSearchNum:add')")
    @Log(title = "搜索关键词+次数记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KeywordSearchNum keywordSearchNum) {
        return toAjax(keywordSearchNumService.insertKeywordSearchNum(keywordSearchNum));
    }

    /**
     * 修改搜索关键词+次数记录
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordSearchNum:edit')")
    @Log(title = "搜索关键词+次数记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KeywordSearchNum keywordSearchNum) {
        return toAjax(keywordSearchNumService.updateKeywordSearchNum(keywordSearchNum));
    }

    /**
     * 删除搜索关键词+次数记录
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordSearchNum:remove')")
    @Log(title = "搜索关键词+次数记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(keywordSearchNumService.deleteKeywordSearchNumByIds(ids));
    }
}
